package mmc.server.shell.ops;

import mmc.server.shell.*;

public abstract class Function extends Operation {

    protected ArgumentList arguments;

    protected Function(String text, String name, int argC, boolean atLeast) throws ShellException {
    	this(text, name, argC, atLeast, ",");
    }
    
    private int argC;
    private boolean atLeast;
    private String argsSeparator;
    
    protected Function(String text, String name, int argC, boolean atLeast, String argsSeparator) throws ShellException {
    	super(text);
    	
    	this.argC = argC;
    	this.atLeast = atLeast;
    	this.argsSeparator = argsSeparator;
    	
    	parse(name, false, true);
    	/*
        super(text = text.trim());

        if (!text.toUpperCase().startsWith(name.toUpperCase())) {
            throw new OperationNotAcceptedException(false, text + " does not contain " + name);
        }

        if (Shell.OP_PARSE_TRACE > 1) {
            System.out.println("successfully detected a " + this.getClass().toString());
        }

        arguments = new ArgumentList(text.substring(name.length()), argC, atLeast, argsSeparator);*/
    }

    protected Operation parseRValue(String text) throws ShellException{
    	return arguments = new ArgumentList(text, argC, atLeast, argsSeparator);
    }
    
    abstract public double execute();

    public String toString() {
        return this.getClass().toString() + ": " + text;
    }
    
    public static PriorityType getPriorityType(){
        return PriorityType.FUNCTION;
    }
}
